package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2018/12/15 15:31
 * @description
 */
public class Code922 {
    public static void main(String[] args) {
        new Code922().sortArrayByParityII(new int[] {4, 2, 5, 7});
    }

    public int[] sortArrayByParityII(int[] A) {
        int[] result = new int[A.length];
        int[] temp = new int[A.length];
        int start = 0;
        int end = A.length - 1;
        for (int i = 0; i < A.length; i++) {
            if (A[i] % 2 == 0) {
                temp[start++] = A[i];
            } else {
                temp[end--] = A[i];
            }
        }
        int half = A.length / 2;

        for (int i = 0, j = 0; i < half; i++) {
            result[j] = temp[i];
            result[j + 1] = temp[half + i];
            j += 2;
        }

        return result;
    }
}
